package com.xgg.taiwuinfo.filter.fc;

import android.content.Context;
import android.util.Log;

import com.xgg.taiwuinfo.R;
import com.xgg.taiwuinfo.filter.FC_CompareSelect;
import com.xgg.taiwuinfo.filter.FilterComponent;
import com.xgg.taiwuinfo.gongfa.base.Gongfa;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FCLevelCompareSelect extends FC_CompareSelect {
    public FCLevelCompareSelect(JSONObject obj , Context ctx)
    {
        mTypeId = FilterComponent.FT_LEVEL_COMP_SELECT;
        if (obj != null) {
            try {
                ReadCompare = obj.getInt("c");
                ReadValue = obj.getInt("v");
            } catch (Exception e) {
                Log.d("LoadJson", e.getLocalizedMessage());
                ReadCompare = FC_EQUAL;
                ReadValue = 1;
            }
        }
        else {
            ReadCompare = FC_EQUAL;
            ReadValue = 1;
        }
        TempValue = ReadValue;
        TempCompare = ReadCompare;

        FieldStr = "功法品级";
        if (mValueMap == null) {
            mValueMap = new ArrayList<>();
            Map<String, String> map;

            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_1));
            map.put("v",  "1");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_2));
            map.put("v", "2");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_3));
            map.put("v", "3");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_4));
            map.put("v", "4");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_5));
            map.put("v", "5");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_6));
            map.put("v", "6");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_7));
            map.put("v", "7");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_8));
            map.put("v", "8");
            mValueMap.add(map);
            map = new HashMap<>();
            map.put("f", ctx.getString(R.string.level_9));
            map.put("v", "9");
            mValueMap.add(map);
        }

        if (mCompMap == null) {
            mCompMap = new ArrayList<>();
        }
        else {
            mCompMap.clear();
        }
        Map<String, String> map;

        map = new HashMap<>();
        map.put("f", "低于");
        map.put("v",  FC_GREATER + "");
        mCompMap.add(map);
        map = new HashMap<>();
        map.put("f", "不高于");
        map.put("v", FC_GREATERCONTAIN + "");
        mCompMap.add(map);
        map = new HashMap<>();
        map.put("f", "等于");
        map.put("v", FC_EQUAL + "");
        mCompMap.add(map);
        map = new HashMap<>();
        map.put("f", "不低于");
        map.put("v", FC_SMALLERCONTAIN + "");
        mCompMap.add(map);
        map = new HashMap<>();
        map.put("f", "高于");
        map.put("v", FC_SMALLER + "");
        mCompMap.add(map);
    }

    @Override
    public String FilterGongfa(Gongfa gongfa){
        switch (ReadCompare)
        {
            case FC_GREATER:
                if (gongfa.mLevel > ReadValue)
                    return "";
                else
                    return null;
            case FC_GREATERCONTAIN:
                if (gongfa.mLevel >= ReadValue)
                    return "";
                else
                    return null;
            case FC_EQUAL:
                if (gongfa.mLevel == ReadValue)
                    return "";
                else
                    return null;
            case FC_SMALLERCONTAIN:
                if (gongfa.mLevel <= ReadValue)
                    return "";
                else
                    return null;
            case FC_SMALLER:
                if (gongfa.mLevel < ReadValue)
                    return "";
                else
                    return null;
            default:
                return null;
        }

    }

    @Override
    public List<Map<String, String>> getFieldString(Context ctx){
        List<Map<String, String>> mCompMap = new ArrayList<>();

        Map<String, String> map;

        map = new HashMap<>();
        map.put("f", FieldStr);
        map.put("v",   "0");
        mCompMap.add(map);

        return mCompMap;
    }

    @Override
    public List<Map<String, String>> getValueMap(Context ctx)
    {


        return mValueMap;
    }

    @Override
    public List<Map<String, String>> getCompareString(Context ctx){


        return mCompMap;
    }

}
